package com.xueyi.tesla.exceptions;

import com.xueyi.tesla.constants.SystemCode;
import lombok.Data;
import org.springframework.util.StringUtils;

/**
 * @author LuQi
 * @类描述 深造异常类
 * @时间 2021/6/19
 */
@Data
public class BusinessException extends RuntimeException {

    public int code;
    public Object o;

    public BusinessException(String msg) {
        super(msg);
        this.code = SystemCode.QUERY_CHECK_ERROR;
    }

    public BusinessException(int code, String msg) {
        super(msg);
        this.code = code;
    }


    public BusinessException(int code, String msg, Object o) {
        super(msg);
        this.code = code;
        this.o = o;
    }

    public static void isNull(Object o, String msg) throws BusinessException {

        // 判断是否为空
        if (o == null) {
            throw new BusinessException(SystemCode.QUERY_CHECK_ERROR, msg);
        }
        if (o instanceof String && !StringUtils.hasLength(o.toString())) {
            throw new BusinessException(SystemCode.QUERY_CHECK_ERROR, msg);
        }
    }

}
